﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class editEmployeeRecordsModule : Form
    {
        int selectedindex=-1;
        percentDeduction form1;
        selection parent;
        //------Charge--------
        ChargeController tipC = new ChargeController();
        ChargeController salaryC = new ChargeController();
        //-----Employee-------
        EmployeeController employeeListC = new EmployeeController();
        EmployeeController employeeInfoC = new EmployeeController();
        //----Attendance------
        SemilateController semilateC = new SemilateController();
        LateAbsenceController LateAbsenceC = new LateAbsenceController();

        String selectedFname, selectedLname;
        TextBox salaryamnt, sssamnt, phamnt; //amount
        String salaryval, sssval, phval;

        public editEmployeeRecordsModule(selection parent)
        {
            this.parent = parent;
            InitializeComponent();
            salaryamnt = (TextBox)informationSalaryTextBox.Controls[1];
            sssamnt = (TextBox)informationSssTextBox.Controls[1];
            phamnt = (TextBox)informationPhilhealthTextBox.Controls[1];
            salaryamnt.TextChanged += new EventHandler(amnt_TextChanged);
            sssamnt.TextChanged += new EventHandler(amnt_TextChanged);
            phamnt.TextChanged += new EventHandler(amnt_TextChanged);
            salaryamnt.Validating += new CancelEventHandler(amnt_Validating);
            sssamnt.Validating += new CancelEventHandler(amnt_Validating);
            phamnt.Validating += new CancelEventHandler(amnt_Validating);
            salaryval = salaryamnt.Text;
            sssval = sssamnt.Text;
            phval = phamnt.Text;
            attendancePicker.SelectedIndex = 0;
            enabledisableInformation(false);
            initializeContent();
        }

        private void back_Click(object sender, EventArgs e)
        {
            parent.Show();
            this.Hide();
        }
        //--------------Charges---------------------------------------
        private void salaryChargeAdd_Click(object sender, EventArgs e)
        {
            if (editEmployeeList.SelectedIndex != -1)
            {
                addEditChargeModule form = new addEditChargeModule(this, 0, 1);
                form.Text = "Add Salary Charge";
                form.ShowDialog();
            }
            else
            {
                MessageBox.Show("Please select an employee in the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void salaryChargeEdit_Click(object sender, EventArgs e)
        {
            if (editEmployeeList.SelectedIndex != -1)
            {
                if (salaryChargeTable.Rows.Count > 0)
                {
                    addEditChargeModule form = new addEditChargeModule(this, 1, 1);
                    form.Text = "Edit Salary Charge";
                    form.ShowDialog();
                }
                else
                {
                    MessageBox.Show("No charge to edit.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Please select an employee in the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void tipChargeAdd_Click(object sender, EventArgs e)
        {
            if (editEmployeeList.SelectedIndex != -1)
            {
                addEditChargeModule form1 = new addEditChargeModule(this, 0, 0);
                form1.Text = "Add Tip Charge";
                form1.ShowDialog();
            }
            else
            {
                MessageBox.Show("Please select an employee in the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void tipChargeEdit_Click(object sender, EventArgs e)
        {
            if (editEmployeeList.SelectedIndex != -1)
            {
                if (tipChargeTable.Rows.Count > 0)
                {
                    addEditChargeModule form = new addEditChargeModule(this, 1, 0);
                    form.Text = "Edit Tip Charge";
                    form.ShowDialog();
                }
                else
                {
                    MessageBox.Show("No charge to edit.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
                MessageBox.Show("Please select an employee in the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public String getChargeSelectedDate(int typeOfCharge)
        {
            String[] date;
            if (typeOfCharge == 0)
                date = tipChargeTable.SelectedRows[0].Cells[0].Value.ToString().Split(' ');
            else
                date = salaryChargeTable.SelectedRows[0].Cells[0].Value.ToString().Split(' ');
            return date[0];
        }

        public decimal getChargeAmount(int typeOfCharge)
        {
            if (typeOfCharge == 0)
                return Decimal.Parse(tipChargeTable.SelectedRows[0].Cells[1].Value.ToString());
            else
                return Decimal.Parse(salaryChargeTable.SelectedRows[0].Cells[1].Value.ToString());
        }

        public String getChargeDescription(int typeOfCharge)
        {
            if (typeOfCharge == 0)
                return tipChargeTable.SelectedRows[0].Cells[2].Value.ToString();
            else
                return salaryChargeTable.SelectedRows[0].Cells[2].Value.ToString();
        }

        private void tipChargeDelete_Click(object sender, EventArgs e)
        {
            if (tipChargeTable.Rows.Count > 0)
            {
                DialogResult result = MessageBox.Show("Are you sure you want to delete the selected charge?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result != DialogResult.Yes)
                {
                    //do nothing
                }
                else
                {
                    DateTime date = DateTime.Parse(tipChargeTable.SelectedRows[0].Cells[0].Value.ToString());
                    double amount = ((double)getChargeAmount(0));
                    string description = getChargeDescription(0);
                    bool success = new ChargeController().deleteCharge(0, date.ToString("yyyy-MM-dd"), amount, description);
                    if (success)
                    {
                        initializeContent();
                    }
                }
            }
            else
            {
                MessageBox.Show("No charge to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void salaryChargeDelete_Click(object sender, EventArgs e)
        {
            if (salaryChargeTable.Rows.Count > 0)
            {
                DialogResult result = MessageBox.Show("Are you sure you want to delete the selected charge?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result != DialogResult.Yes)
                {
                    //do nothing
                }
                else
                {
                    DateTime date = DateTime.Parse(salaryChargeTable.SelectedRows[0].Cells[0].Value.ToString());
                    double amount = ((double)getChargeAmount(1));
                    string description = getChargeDescription(1);
                    bool success = new ChargeController().deleteCharge(1, date.ToString("yyyy-MM-dd"), amount, description);
                    if (success)
                    {
                        initializeContent();
                    }
                }
            }
            else
            {
                MessageBox.Show("No charge to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //----------------------------Adding Editing Employee Info---------------------------------
        private void setEmployeeInfo(Employee employeeInfoSource)
        {
            informationFirstNameTextBox.Text = employeeInfoSource.firstName;
            informationLastNameTextBox.Text = employeeInfoSource.lastName;
            informationSalaryTextBox.Value = (decimal)employeeInfoSource.salary;
            informationWorkHoursTextBox.Value = employeeInfoSource.workHours;
            informationPayingBasisDropDownList.SelectedIndex = employeeInfoSource.payingBasis;
            informationPositionDropDownList.SelectedIndex = employeeInfoSource.position;
            informationStatusDropDownList.SelectedIndex = employeeInfoSource.employeeStatus;
            informationContractStartTextBox.Value = DateTime.Parse(employeeInfoSource.contractStart);
            informationContractEnd.Value = DateTime.Parse(employeeInfoSource.contractEnd);
            informationSssTextBox.Value = (decimal)employeeInfoSource.SSS;
            informationPhilhealthTextBox.Value = (decimal)employeeInfoSource.PhilHealth;
            informationDebtTextBox.Value = (decimal)employeeInfoSource.debt;
            informationBonusesTextBox.Value = (decimal)employeeInfoSource.bonusesDeductions;
        }

        private void add_Click(object sender, EventArgs e)
        {
            addEmployee form = new addEmployee(this,parent);
            form.ShowDialog();
        }

        private void delete_Click(object sender, EventArgs e)
        {
            Employee employee = new Employee();
            if (editEmployeeList.Items.Count > 0)
            {
                if (editEmployeeList.SelectedIndex != -1)
                {
                    DialogResult result = MessageBox.Show("Are you sure you want to delete the selected employee?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (result != DialogResult.Yes)
                    {
                        //do nothing
                    }
                    else
                    {
                        string lastName = editEmployeeList.SelectedItem.ToString().Split(',')[0];
                        string firstName = editEmployeeList.SelectedItem.ToString().Split(',')[1].Trim();
                        bool success = new EmployeeController().deleteEmployee(firstName, lastName);
                        if (success)
                        {
                            initializeContent();
                            parent.reInitializeContent();
                            editEmployeeList.SelectedIndex = -1;
                            setEmployeeInfo(employee);
                        }
                    }
                }
                else
                    MessageBox.Show("Please select an employee to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("No employee to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void editEmployeeList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (editEmployeeList.SelectedIndex != -1)
            {
                Employee employeeInfoSource = new Employee();
                BindingSource tipChargeSource = new BindingSource();
                BindingSource salaryChargeSource = new BindingSource();
                BindingSource lateAbsencesSource = new BindingSource();
                BindingSource semilateSource = new BindingSource();
                //---------Employee--------
                selectedFname = editEmployeeList.SelectedItem.ToString().Split(',')[1].Trim();
                selectedLname = editEmployeeList.SelectedItem.ToString().Split(',')[0];
                employeeInfoSource = employeeInfoC.getInformation(selectedFname, selectedLname);
                enabledisableInformation(false);
                informationEdit.Text = "Edit";
                //----------Charges--------
                tipChargeSource.DataSource = tipC.getData(selectedLname, selectedFname, 0);
                salaryChargeSource.DataSource = salaryC.getData(selectedLname, selectedFname, 1);
                tipChargeTable.DataSource = tipChargeSource;
                salaryChargeTable.DataSource = salaryChargeSource;
                setEmployeeInfo(employeeInfoSource);
                //--------Attendance-------
                lateAbsencesSource.DataSource = LateAbsenceC.getData(selectedLname, selectedFname);
                semilateSource.DataSource = semilateC.getData(selectedLname, selectedFname);
                lateAbsencesTable.DataSource = lateAbsencesSource;
                semilateTable.DataSource = semilateSource;
                selectedindex = editEmployeeList.SelectedIndex;
            }
        }

        private void informationEdit_Click(object sender, EventArgs e)
        {
            if (parent.getPrivilege() == 1)
            {
                if (informationEdit.Text == "Edit")
                {
                    if (editEmployeeList.SelectedIndex == -1)
                        MessageBox.Show("Please select an employee to edit.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    else
                    {
                        enabledisableInformation(true);
                        informationEdit.Text = "Save";
                    }
                }
                else
                {
                    DialogResult result = MessageBox.Show("Are you sure you want to make the changes?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (result != DialogResult.Yes)
                    {
                        //do nothing
                    }
                    else
                    {
                        Boolean nameListContains = false;
                        string lastName = editEmployeeList.SelectedItem.ToString().Split(',')[0];
                        string firstName = editEmployeeList.SelectedItem.ToString().Split(',')[1].Trim();
                        string name = lastName + ", " + firstName;
                        List<string> employeeList = new List<string>();
                        foreach (string X in editEmployeeList.Items)
                        {
                            employeeList.Add(X);
                        }
                        employeeList.Remove(name);
                        foreach (string N in employeeList)
                        {
                            if (string.Compare(N, name, true) == 0)
                            {
                                nameListContains = true;
                            }
                        }
                        if (informationFirstNameTextBox.Text == "" || informationLastNameTextBox.Text == "")
                        {
                            MessageBox.Show("No field should be empty.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            informationLastNameTextBox.Text = lastName;
                            informationFirstNameTextBox.Text = firstName;
                        }
                        else if (nameListContains && !(string.Compare(informationFirstNameTextBox.Text, firstName, true) == 0 && string.Compare(informationLastNameTextBox.Text, lastName, true) == 0))
                        {
                            MessageBox.Show("An employee with the same name already exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (DateTime.Compare(informationContractEnd.Value, informationContractStartTextBox.Value) <= 0)
                        {
                            MessageBox.Show("Please set contract end at a future date.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else
                        {
                            Employee employee = new Employee();
                            employee.firstName = informationFirstNameTextBox.Text;
                            employee.lastName = informationLastNameTextBox.Text;
                            employee.salary = (double)informationSalaryTextBox.Value;
                            employee.workHours = (int)informationWorkHoursTextBox.Value;
                            employee.payingBasis = informationPayingBasisDropDownList.SelectedIndex;
                            employee.position = informationPositionDropDownList.SelectedIndex;
                            employee.contractStart = informationContractStartTextBox.Value.ToString("yyyy-MM-dd");
                            employee.contractEnd = informationContractEnd.Value.ToString("yyyy-MM-dd");
                            employee.SSS = (double)informationSssTextBox.Value;
                            employee.PhilHealth = (double)informationPhilhealthTextBox.Value;
                            employee.debt = (double)informationDebtTextBox.Value;
                            employee.employeeStatus = informationStatusDropDownList.SelectedIndex;
                            employee.bonusesDeductions = (double)informationBonusesTextBox.Value;
                            bool success = new EmployeeController().editEmployee(employee, lastName, firstName);
                            if (success)
                            {
                                initializeContent();
                                editEmployeeList.SelectedIndex = editEmployeeList.Items.IndexOf(employee.lastName + ", " + employee.firstName);
                                enabledisableInformation(false);
                                informationEdit.Text = "Edit";
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Cannot edit the information. You have insufficient access privileges.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void informationCancel_Click(object sender, EventArgs e)
        {
            Employee employeeInfoSource = new Employee();
            enabledisableInformation(false);
            informationEdit.Text = "Edit";
            employeeInfoSource = employeeInfoC.getInformation(selectedFname, selectedLname);
            setEmployeeInfo(employeeInfoSource);
        }

        private void enabledisableInformation(bool flag)
        {
            informationFirstNameTextBox.Enabled = flag;
            informationLastNameTextBox.Enabled = flag;
            informationSalaryTextBox.Enabled = flag;
            informationWorkHoursTextBox.Enabled = flag;
            informationPayingBasisDropDownList.Enabled = flag;
            informationPositionDropDownList.Enabled = flag;
            informationStatusDropDownList.Enabled = flag;
            informationContractStartTextBox.Enabled = flag;
            informationContractEnd.Enabled = flag;
            informationSssTextBox.Enabled = flag;
            informationPhilhealthTextBox.Enabled = flag;
            informationDebtTextBox.Enabled = flag;
            informationBonusesTextBox.Enabled = flag;
            informationCancel.Visible = flag;
        }

        public ListBox getEmployeesList()
        {
            return editEmployeeList;
        }

        private void editEmployeePercentDeductionButton_Click(object sender, EventArgs e)
        {
            if (form1 == null)
            {
                form1 = new percentDeduction(editEmployeeList);
            }
            form1.ShowDialog();
            form1.initializeContent();
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            DialogResult result = MessageBox.Show("Are you sure you want to exit the program?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (result == DialogResult.No)
                e.Cancel = true;
            else
                Environment.Exit(1);
        }

        public void initializeContent()
        {
            string name;
            BindingSource tipChargeSource = new BindingSource();
            BindingSource salaryChargeSource = new BindingSource();
            DataTable employeeListSource = new DataTable();
            BindingSource lateAbsencesSource = new BindingSource();
            BindingSource semilateSource = new BindingSource();
            //------------------------------------------------------
            tipChargeSource.DataSource = tipC.getData(selectedLname, selectedFname, 0);
            salaryChargeSource.DataSource = salaryC.getData(selectedLname, selectedFname, 1);
            employeeListSource = employeeListC.getNames();
            lateAbsencesSource.DataSource = LateAbsenceC.getData(selectedLname, selectedFname);
            semilateSource.DataSource = semilateC.getData(selectedLname, selectedFname);
            //------------------------------------------------------
            tipChargeTable.DataSource = tipChargeSource;
            salaryChargeTable.DataSource = salaryChargeSource;
            lateAbsencesTable.DataSource = lateAbsencesSource;
            semilateTable.DataSource = semilateSource;

            editEmployeeList.Items.Clear();
            name = selectedLname + ", " + selectedFname;
            for(int i=0 ; i< employeeListSource.Rows.Count; i++)
                editEmployeeList.Items.Add((employeeListSource.Rows[i][0].ToString() + ", " + employeeListSource.Rows[i][1].ToString()));
        }

         private void addAttendance_Click(object sender, EventArgs e)
        {
            if (editEmployeeList.SelectedIndex != -1)
            {
                if (attendancePicker.SelectedIndex == 2)
                {
                    addEditSemilate addsemilate = new addEditSemilate(this, 0);
                    addsemilate.Text = "Add Semi-Late";
                    addsemilate.ShowDialog();
                }
                else if (attendancePicker.SelectedIndex == 0)
                {
                    addEditLateAbsences addlate = new addEditLateAbsences(this, 0);
                    addlate.Text = "Add Late";
                    addlate.ShowDialog();
                }
                else
                {
                    addEditLateAbsences addabsence = new addEditLateAbsences(this, 1);
                    addabsence.Text = "Add Absence";
                    addabsence.ShowDialog();
                }
            }
            else
                MessageBox.Show("Please select an employee to edit.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void editAttendance_Click(object sender, EventArgs e)
        {
            if (editEmployeeList.SelectedIndex != -1)
            {
                if (attendancePicker.SelectedIndex == 2)//semilate
                {
                    if (semilateTable.Rows.Count > 0)
                    {
                        addEditSemilate editsemilate = new addEditSemilate(this, 1);
                        editsemilate.Text = "Edit Semi-Late";
                        editsemilate.ShowDialog();
                    }
                    else
                        MessageBox.Show("No record to edit", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (attendancePicker.SelectedIndex == 0)//late
                {
                    if (lateAbsencesTable.Rows.Count > 0)
                    {
                        addEditLateAbsences editlate = new addEditLateAbsences(this, 2);
                        editlate.Text = "Edit Late";
                        editlate.ShowDialog();
                    }
                    else
                        MessageBox.Show("No record to edit", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else//absent
                {
                    if (lateAbsencesTable.Rows.Count > 0)
                    {
                        addEditLateAbsences editabsence = new addEditLateAbsences(this, 3);
                        editabsence.Text = "Edit Absence";
                        editabsence.ShowDialog();
                    }
                    else
                        MessageBox.Show("No record to edit", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
                MessageBox.Show("Please select an employee to edit.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void deleteAttendance_Click(object sender, EventArgs e)
        {
            if (editEmployeeList.SelectedIndex != -1)
            {
                if (attendancePicker.SelectedIndex == 2) // semilate
                {
                    if (semilateTable.Rows.Count > 0)
                    {
                        DialogResult result = MessageBox.Show("Are you sure you want to delete the selected record?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result == DialogResult.Yes)
                        {
                            DateTime date = DateTime.Parse(semilateTable.SelectedRows[0].Cells[0].Value.ToString());
                            bool success = new SemilateController().deleteRecord(date.ToString("yyyy-MM-dd"), selectedLname, selectedFname);

                            if (success)
                            {
                                initializeContent();
                                editEmployeeList.SelectedIndex = editEmployeeList.Items.IndexOf(selectedLname + ", " + selectedFname);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("No semi-late record to delete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else if (attendancePicker.SelectedIndex == 0)
                {
                    if (lateAbsencesTable.Rows.Count > 0)
                    {
                        DialogResult result = MessageBox.Show("Are you sure you want to delete the selected record?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result == DialogResult.Yes)
                        {
                            bool success = new LateAbsenceController().deleteLates(getSelectedLastName(), getSelectedFirstName(), getAbsentSelectedDate());
                            if (success)
                            {
                                initializeContent();
                                editEmployeeList.SelectedIndex = editEmployeeList.Items.IndexOf(selectedLname + ", " + selectedFname);
                            }
                        }
                    }
                    else
                        MessageBox.Show("No late record to delete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if (lateAbsencesTable.Rows.Count > 0)
                    {
                        DialogResult result = MessageBox.Show("Are you sure you want to delete the selected record?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result == DialogResult.Yes)
                        {
                            bool success = new LateAbsenceController().deleteAbsences(getSelectedLastName(), getSelectedFirstName(), getAbsentSelectedDate());
                            if (success)
                            {
                                initializeContent();
                                editEmployeeList.SelectedIndex = editEmployeeList.Items.IndexOf(selectedLname + ", " + selectedFname);
                            }
                        }
                    }
                    else
                        MessageBox.Show("No absence record to delete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
                MessageBox.Show("Please select an employee to edit.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public int getEmployeeIndex()
        {
            return editEmployeeList.SelectedIndex;
        }

        public string getSelectedLastName()
        {
            return selectedLname;
        }

        public string getSelectedFirstName()
        {
            return selectedFname;
        }

        public editEmployeeRecordsModule getEditEmployeeRecordsModule()
        {
            return this;
        }

        private void amnt_TextChanged(object sender, EventArgs e)
        {
            if (salaryamnt.Focused || sssamnt.Focused || phamnt.Focused)
            {
                salaryval = salaryamnt.Text;
                sssval = sssamnt.Text;
                phval = phamnt.Text;
            }
        }

        private void amnt_Validating(object sender, CancelEventArgs e)
        {
            if (multipleDecPoints(salaryval) || multipleDecPoints(sssval) || multipleDecPoints(phval))
            {
                MessageBox.Show("Invalid input; too many decimal points.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
                if (salaryval.Equals(".") || sssval.Equals(".") || phval.Equals("."))
                {
                    MessageBox.Show("Invalid input.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    double salarycheck = Double.Parse(salaryval);
                    double ssscheck = Double.Parse(sssval);
                    double phcheck = Double.Parse(phval);
                    if (salarycheck < (double)informationSssTextBox.Minimum || salarycheck > (double)informationSssTextBox.Maximum
                        || ssscheck < (double)informationSssTextBox.Minimum || ssscheck > (double)informationSssTextBox.Maximum
                        || phcheck < (double)informationSssTextBox.Minimum || phcheck > (double)informationSssTextBox.Maximum)
                        MessageBox.Show("Invalid input; out of range.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
        }

        private bool multipleDecPoints(String num)
        {
            int nPoints = 0;
            int i = 0;
            while (nPoints < 2 && i < num.Length)
            {
                if (num[i] == '.')
                    nPoints++;
                i++;
            }
            if (nPoints < 2)
                return false;
            else
                return true;
        }

        public String getSelectedDate()
        {
            String[] date = semilateTable.SelectedRows[0].Cells[0].Value.ToString().Split(' ');
            return date[0];
        }
        public decimal getAmount()
        {
            return Decimal.Parse(semilateTable.SelectedRows[0].Cells[2].Value.ToString());
        }

        public int getHours()
        {
            return int.Parse(semilateTable.SelectedRows[0].Cells[1].Value.ToString());
        }

        public int getAbsences()
        {
            return int.Parse(lateAbsencesTable.SelectedRows[0].Cells[3].Value.ToString());
        }

        public int getLates()
        {
            return int.Parse(lateAbsencesTable.SelectedRows[0].Cells[2].Value.ToString());
        }

        public String getAbsentSelectedDate()
        {
            DateTime date = DateTime.Parse(lateAbsencesTable.SelectedRows[0].Cells[0].Value.ToString());
            return date.ToString("yyyy-MM-dd");
        }

        public decimal getEmployeeHours()
        {
            return informationWorkHoursTextBox.Value;
        }

        //------------new----------------
        public string getEmployeePayingBasis()
        {
            return informationPayingBasisDropDownList.SelectedItem.ToString();
        }

        public double getEmployeeSalary()
        {
            return (double)informationSalaryTextBox.Value;
        }

    }
}
